package cn.le.handler.banks;

import cn.le.bean.enums.EnumMsgCode;
import cn.le.bean.util.NettyMsgUtils;
import cn.le.bean.vo.NettyMsg;
import cn.le.kafka.*;
import cn.le.inf.HandlerCode;
import cn.le.inf.NettyHandler;
import cn.le.util.ConnectionUtil;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Component;

@Component
@HandlerCode(EnumMsgCode.handler_point_send)
public class SendMsgHandler implements NettyHandler {

    @Override
    public void doFilter(ChannelHandlerContext ctx, NettyMsg msg) {
        //给消息接受者发送消息
        ChannelHandlerContext tctx = ConnectionUtil.getByImUserId(msg.getTid());
        if (tctx == null){
            //离线消息
            KafkaUtils.KafkaImUtils.sendOffline(msg);
        }
        tctx.channel().writeAndFlush(msg);
        //回复消息为发送成功
        //ctx.channel().writeAndFlush(ResponseFactory.nettyOk(msg.getId()));
    }
}
